package com.xneure.code.search;

import java.util.HashMap;
import java.util.Map;

public class ResourceNode {
	private Map<Character, ResourceTree> tree = new HashMap<Character, ResourceTree>();

	public void put(String key, Object data) {
		put(key.toCharArray(), data);
	}

	public void put(char[] key, Object data) {
		ResourceTree val = tree.get(key[0]);
		if (val == null) {
			val = new ResourceTree(null);
			tree.put(key[0], val);
		}
		val.put(1, key, data);
	}

	public Object getData(String key) {
		return getData(key.toCharArray());
	}

	private Object getData(char[] charArray) {
		ResourceTree val = tree.get(charArray[0]);
		if (val != null) {
			return val.getData(1, charArray);
		}
		return null;
	}
}
